package gpl.androidcommons.scotlandyard.adapter;

import gpl.androidcommons.R;
import gpl.scotlandyard.beans.basics.Player;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PlayersAdapter extends BaseAdapter {
  private final LayoutInflater inflater;
  private final List<Player> players;

  public PlayersAdapter(List<Player> players, LayoutInflater inflater) {
    this.inflater = inflater;
    this.players = players;
  }

  @Override
  public View getView(int position, View arg1, ViewGroup container) {
    LinearLayout playerView = (LinearLayout) inflater.inflate(R.layout.player_thumb, container, false);

    TextView textView = (TextView) playerView.findViewById(R.id.tv_name);
    textView.setText(players.get(position).getName());

    GridView gridView = (GridView) playerView.findViewById(R.id.gv_tickets);
    PlayerTicketsAdapter adapter = new PlayerTicketsAdapter(players.get(position), inflater);
    gridView.setAdapter(adapter);
    gridView.setNumColumns(adapter.getCount());
    return playerView;
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public Object getItem(int position) {
    return players.get(position);
  }

  @Override
  public int getCount() {
    return players.size();
  }
}
